$(document).ready(function() {	
	$("#frmAdd").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			pusername:{
				required 			: true,
				rangelength			: [5,30],
				validateFormat		: true,
				validateUsername	: true
			},
			ppassword : {
				required			: true,
				minlength			: 5,
				equalTo				: '#ppassword_confirm'
			},
			ppassword_confirm: {
				required			: true
			}
		},
		messages: {
			pusername:{
				required 			: username_required,
				rangelength			: username_range,
				validateFormat		: username_format,
				validateUsername	: username_validate
			},
			ppassword : {
				required			: password_required,
				minlength			: password_minlength,
				equalTo				: password_notmatch
			},
			ppassword_confirm: {
				required			: password_confirm_required
			}
		},
		errorPlacement: function(label, element) {			
			var id = element.attr('id');			
			label.insertAfter($('#' + id));			
		},
		submitHandler: function(form) {				
			form.submit();
		}
	});	
	$.validator.addMethod('validateFormat', function() {
		var strUsername = $('#pusername').val();
		return validateUsername(strUsername);
	});
	$.validator.addMethod('validateUsername', function(){	
		var result 		= true;
		var strUsername	= $('#pusername').val();
		var strUrl 		= HOST_BACKEND + 'valid/isvalidusername';
		$.ajax({
			cache	: false,
            async	: false,
            type	: 'POST',
			data	: 'username=' + strUsername,
			url		: strUrl,
			success	: function(response) {
				result = (response == 1) ? true : false;
			}
		});
		return result;
	});
	$.validator.addMethod('validateBlacklist', function(){											
		return true;											
	});
});